#!/usr/bin/env python
# -*- coding: utf-8 -*-
# datetime: 10/12/2023 下午9:51
# Author: name
# File: environment_model.py
# ide: PyCharm
# description: 环境相关数据库模型

from datetime import datetime
from typing import List
from pydantic import BaseModel
from tortoise import fields
from tortoise.models import Model


class EnvironmentModel(Model):
    id = fields.IntField(pk=True, description="主键")
    name = fields.CharField(max_length=255, description="环境名称")
    address = fields.CharField(max_length=255, description="环境地址")
    username = fields.CharField(max_length=255, description="用户名")
    password = fields.CharField(max_length=255, description="密码")
    login_temp_id = fields.IntField(description="登录模板id")
    description = fields.CharField(max_length=255, description="描述信息")
    created_at = fields.CharField(max_length=255, description="创建时间")

    updated_at = fields.CharField(max_length=255, description="更新时间")

    class Meta:
        table = "environments"


class EnvironmentIn(BaseModel):
    name: str
    address: str
    username: str
    password: str
    login_temp_id: int
    description: str = None


class EnvironmentOut(BaseModel):
    id: int
    name: str
    address: str
    username: str
    password: str
    description: str
    created_at: str
    updated_at: str
    login_temp_id: int


class EnvironmentPage(BaseModel):
    total: int
    page_size: int
    current_page: int
    search_key: str = None
    results: List[EnvironmentOut]
